package com.yan01.nio;

import java.nio.IntBuffer;

/**
 * @author yyh
 * @create 2020-10-31 9:08
 */
public class BasicNio {

    public static void main(String[] args) {
        //举例说明Buffer 的使用 (简单说明)
        //创建一个Buffer, 大小为 5, 即可以存放5个int
        IntBuffer allocate = IntBuffer.allocate(5);
        for (int i = 0; i < allocate.capacity(); i++) {
            allocate.put(i*2);
        }

        //如何从buffer读取数据
        //将buffer转换，读写切换(!!!)
        allocate.flip();
        allocate.position(0);
        System.out.println(allocate.get());
        allocate.limit(3);
        while(allocate.hasRemaining()){
            System.out.println(allocate.get());
        }
    }

}
